Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
observable-callback
Advanced tools
A small utility for simplified creation of callback functions that publishes the argument to an observable stream when called.
A small utility for simplified creation of callback functions that publishes the argument to an observable stream when called.
It's a small wrapper around RxJS Subjects that returns a tuple of the Subject as an observable and the subject's next()
function
const [value$, onValue] = observableCallback()
value$.subscribe((value) => {
// will print "Hello world!"
console.log(value)
})
setTimeout(() => onValue("Hello world!"), 100)
const [greeting$, onPlanet] = observableCallback((planet$) =>
planet$.pipe(map((planet) => `Hello ${planet}!`))
)
greeting$.subscribe((greeting) => {
// will print "Hello world!" after 100ms
console.log(greeting)
})
setTimeout(() => onPlanet("world"), 100)
Sometimes the only way to know when an event happens in different APIs is by providing a function that will be called at some later point. Sometimes it makes sense represent calls to a function as an observable of its called arguments. One example of this can be event handlers in React:
const [clicks$, onClick] = observableCallback()
clicks$.subscribe(() => {
console.log("User clicked the button")
})
render(<button onClick={onClick}>Click me!</button>)
Another use case could be to provide an action stream, and a way of dispatching actions. For example, here's a simple router that exposes the current page as an observable stream, and a function to call in order to navigate to another page:
// page.js
const [onNavigate$, onNavigate] = observableCallback()
export const currentPage$ = onNavigate$.pipe(
switchMap((page) => {
return loadPage(page)
})
)
export const navigate = onNavigate
//... some other part of the application
function SomeComponent() {
return <button onClick={() => navigate("page2")}>Go to page 2</button>
}
function observableCallback<T>(): [Observable<T>, (argument: T) => void]
function observableCallback<T, K>(
operator: OperatorFunction<T, K>
): [Observable<T>, (argument: T) => void]
MIT
FAQs
A small utility for simplified creation of callback functions that publishes the argument to an observable stream when called.
The npm package observable-callback receives a total of 97,752 weekly downloads. As such, observable-callback popularity was classified as popular.
We found that observable-callback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.